﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using messageboard.dal;
using messageboard.bll;
using System.Data;


namespace messageboard
{
    public partial class message : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {   //分配未登录用户id
            if (Session["id"]==null)
            {
                Session["id"] = 1;
                Session["name"] = "匿名";
            }

            //数据绑定
            PagedDataSource pd = new PagedDataSource();
            pd.DataSource = new MessageBll().showmessage().DefaultView;
            pd.AllowPaging = true;
            pd.PageSize = 10;
            pd.CurrentPageIndex = Convert.ToInt32(Request.QueryString["page"]);
            int i = pd.CurrentPageIndex;
            Repeater1.DataSource = pd;
            Repeater1.DataBind();

            //当前登录用户信息
            UserBll userbll = new UserBll();
            DataTable dt= userbll.getuserdetail(Session["name"].ToString());
            string name=dt.Rows[0]["name"].ToString();
            string face = dt.Rows[0]["face"].ToString();
            Label2.Text = name;                                 //用户名
            Image2.ImageUrl = "~/images/face/(" + face + ").png"; //用户头像
            

            //判断当前页码
            if (i < pd.PageCount)
            {
                fp.NavigateUrl = "?page=" + (i + 1);
            }
            else
            {
                fp.NavigateUrl = "?page=" + i;
            }
            if (i > 0)
            {
                bp.NavigateUrl="?page=" + (i - 1);
            }
            else
            {
                bp.NavigateUrl="?page=" + i;
            }

            


        }



        protected void Button2_Click(object sender, EventArgs e)
        {
            int id;
            MessageBll bll = new MessageBll();
            //判断是否登陆
            if (Session["id"] == null)
            {
                id = 1;
            }
            else
            {
                string a = Session["id"].ToString();
                id = Convert.ToInt32(a);
            }
            if (bll.addmessage(TextBox3.Text,TextBox1.Text, id))//添加留言
            {
                Response.Redirect("message.aspx");
            }
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {

        }
    }
}